﻿/**
 * Created by Administrator on 2017/8/21.
 */
var fontSize;
var pieConfi;
var child;
var pageTimer={};
window.onload = function () {
    fontSize = parseFloat($("html").css("font-size"));
}

//封装小饼图
var smallPie = function (data,i) {
    var width = 700;
    var height = 700;
    var childreChart=document.getElementById('childreChart');
    childreChart.width = adaptation1(width);
    childreChart.height = adaptation1(height);

    var cxt = childreChart.getContext("2d");
    cxt.translate(adaptation1(width/2),adaptation1(height/2));
    cxt.rotate(-3*Math.PI/8);//设定每次旋转的度数

    var pieConfiChild=[];

    for(var j=0;j<data.length;j++){
        pieConfiChild[j] = {
            pie:{
                x: adaptation1(0),     //圆心的x轴坐标值
                y: adaptation1(0),    //圆心的y轴坐标值
                r: adaptation1(width/3.5),  //圆的半径
                w:adaptation1(width/8),     //圆的弧度宽
                offset:15,         //偏移值
                sleep:20
            },
            data:data[j]
        }
    }
    // 实例化对象
    new Pie(childreChart,pieConfiChild[i],function (dom) {
        //装饰
        //drawChart(dom);
    },function (dom) {
        //添加监听事件
        // addEven(dom,pieConfiChild[i],function (i) {
        // });
    });

}

//封装大饼图
var BigPie = function (data,childData,lineDta,line) {
    var width = 700;
    var height = 700;
    var chart=document.getElementById('chart');
    chart.width = adaptation1(width);
    chart.height = adaptation1(height);
    var cxt = chart.getContext("2d");
    cxt.translate(adaptation1(width/2),adaptation1(height/2));
    cxt.rotate(-3*Math.PI/8);//设定每次旋转的度数
    pieConfi = {
        pie:{
            x: adaptation1(0),     //圆心的x轴坐标值
            y: adaptation1(0),    //圆心的y轴坐标值
            r: adaptation1(width/4.7),  //圆的半径
            w:adaptation1(width/7),     //圆的弧度宽
            offset:10 ,         //偏移值
            sleep:30,

        },
        data:data
    }
    // 实例化对象
    new Pie(chart,pieConfi,function (dom) {
        //装饰
        //drawChartMain(dom);
        // drawChartMainDynamic(dom);
    },function (dom) {
        setTimeout(function () {
            //添加监听事件
            addEven(dom,pieConfi,function (i) {
                for(var each in pageTimer){
                    clearTimeout(pageTimer[each]);
                }
                $("#Line").css("transform","translate3d(0,0,0) scale3d(.5,.5,.5)");
                line.onload(lineDta);
                $("#chartSmall").show();
                new smallPie(childData,i);
            });
        },1000);
    });
}

//封装饼图对象
var Pie = function (dom,pieConfi,addConfi,addConfiDynamic) {
    //绘制圆饼图
    drawPie(dom,pieConfi,function () {
        addConfi(dom);
    });
    addConfiDynamic(dom);
}

/*
 * 绘制圆饼图
 * **/
function drawPie(dom,pieConfi,fun) {
    var data = pieConfi.data;
    //添加添加动画
    var percentage = 0;
    var newPieConfi = clone(pieConfi);
    var newData = newPieConfi.data;
    addAnim();
    function addAnim() {
        pageTimer['index'+percentage] = setTimeout(function () {
            if (percentage <= 1){
                for (var i=0;i<newData.length;i++){
                    newData[i].value = data[i].value*percentage;
                }
                alertChart(dom, newPieConfi, function () {
                    fun();
                });
                addAnim();
            }else {
                alertChart(dom, pieConfi, function () {
                    fun();
                });
            }
        },pieConfi.pie.sleep);
        percentage+=0.05;
    }
}

/**
 * 绘画图表
 * dom    画布元素
 * obj    配置对象
 * a、b、c代表不同的进度
 * **/
function drawChart(dom) {
    var width = dom.width*16/fontSize;
    var height = dom.height*16/fontSize;
    if(dom.getContext) {
        //获取对应的CanvasRenderingContext2D对象(画笔)
        var ctx = dom.getContext("2d");
        var circle = {
            x: adaptation1(width/2),     //圆心的x轴坐标值
            y: adaptation1(height/2),    //圆心的y轴坐标值
            r: adaptation1(width/2-1),  //圆的半径
            w:adaptation1(1),     //圆的弧度宽
            color:"#ffffff",  //画笔原色
            s:0,       //起始角
            e:Math.PI,    //结束角
            c:true             //旋转方向
        };
        drawArc(ctx,circle);
        var circle = {
            x: adaptation1(width/2),     //圆心的x轴坐标值
            y: adaptation1(height/2),    //圆心的y轴坐标值
            r: adaptation1(width/2-12),  //圆的半径
            w:adaptation1(1),     //圆的弧度宽
            color:"#ffffff",  //画笔原色
            s:Math.PI/2,       //起始角
            e:3*Math.PI/2,    //结束角
            c:true             //旋转方向
        };
        drawArc(ctx,circle);
        var circle = {
            x:adaptation1(width/2),     //圆心的x轴坐标值
            y: adaptation1(height/2),    //圆心的y轴坐标值
            r: adaptation1(width/2-25),  //圆的半径
            w:adaptation1(8),     //圆的弧度宽
            color:"#374d78",  //画笔原色
            s:0.6*Math.PI,       //起始角
            e:1.35*Math.PI,    //结束角
            c:true             //旋转方向
        };
        drawArc(ctx,circle);
        var circle = {
            x: adaptation1(width/2),     //圆心的x轴坐标值
            y: adaptation1(height/2),    //圆心的y轴坐标值
            r: adaptation1(width/2-110),  //圆的半径
            w:adaptation1(7),     //圆的弧度宽
            color:"#8290ab",  //画笔原色
            s:0*Math.PI,       //起始角
            e:0.01*Math.PI,    //结束角
            c:false             //旋转方向
        };
        drawArcDouble(ctx,circle,45,1.2*Math.PI);
        var circle = {
            x: adaptation1(width/2),     //圆心的x轴坐标值
            y: adaptation1(height/2),    //圆心的y轴坐标值
            r: adaptation1(width/2-122),  //圆的半径
            w:adaptation1(10),     //圆的弧度宽
            color:"#FFFFFF",  //画笔原色
            s:1.1*Math.PI,       //起始角
            e:1.11*Math.PI,    //结束角
            c:false             //旋转方向
        };
        drawArcDouble(ctx,circle,45,1.05*Math.PI);
        // //开始一个新的绘制路径
        // ctx.beginPath();
        // //设置字体的颜色为蓝色
        // ctx.fillStyle = "#FFFFFF";
        // //设置字体度宽
        // ctx.font = "bold 30px Arial";
        // ctx.fillText("25", adaptation1(width/2-15), adaptation1(height/2+10));
        // ctx.stroke();
    }else {
        alert("您的浏览器不兼容")
    }
}
/***绘制主图表**/
function drawChartMain(dom) {
    var width = dom.width*16/fontSize;
    var height = dom.height*16/fontSize;
    if(dom.getContext) {
        //获取对应的CanvasRenderingContext2D对象(画笔)
        var ctx = dom.getContext("2d");
        var circle = {
            x: adaptation1(width/2),     //圆心的x轴坐标值
            y: adaptation1(height/2),    //圆心的y轴坐标值
            r: adaptation1(width/2-245),  //圆的半径
            w:adaptation1(1),     //圆的弧度宽
            color:"#6b717d",  //画笔原色
            s:Math.PI/2,       //起始角
            e:9*Math.PI/5,    //结束角
            c:false             //旋转方向
        };
        drawArc(ctx,circle);
        var circle = {
            x: adaptation1(width/2),     //圆心的x轴坐标值
            y: adaptation1(height/2),    //圆心的y轴坐标值
            r: adaptation1(width/2-220),  //圆的半径
            w:adaptation1(1),     //圆的弧度宽
            color:"#6b717d",  //画笔原色
            s:Math.PI/2,       //起始角
            e:9*Math.PI/5,    //结束角
            c:false             //旋转方向
        };
        drawArc(ctx,circle);
        var circle = {
            x: adaptation1(width/2),     //圆心的x轴坐标值
            y: adaptation1(height/2),    //圆心的y轴坐标值
            r: adaptation1(width/2-222),  //圆的半径
            w:adaptation1(1),     //圆的弧度宽
            color:"#6b717d",  //画笔原色
            s:Math.PI/2,       //起始角
            e:9*Math.PI/5,    //结束角
            c:false             //旋转方向
        };
        drawArc(ctx,circle);

        var circle = {
            x: adaptation1(width/2),     //圆心的x轴坐标值
            y: adaptation1(height/2),    //圆心的y轴坐标值
            r: adaptation1(width/2-90),  //圆的半径
            w:adaptation1(3),     //圆的弧度宽
            color:"#FFFFFF",  //画笔原色
            s:4*Math.PI/5,       //起始角
            e:6*Math.PI/5,    //结束角
            c:false             //旋转方向
        };
        drawArc(ctx,circle);

        var circle = {
            x: adaptation1(width/2),     //圆心的x轴坐标值
            y: adaptation1(height/2),    //圆心的y轴坐标值
            r: adaptation1(width/2-90),  //圆的半径
            w:adaptation1(3),     //圆的弧度宽
            color:"#FFFFFF",  //画笔原色
            s:9*Math.PI/5,       //起始角
            e:10*Math.PI/5,    //结束角
            c:false             //旋转方向
        };
        drawArc(ctx,circle);

        var circle = {
            x: adaptation1(width/2),     //圆心的x轴坐标值
            y: adaptation1(height/2),    //圆心的y轴坐标值
            r: adaptation1(width/2-75),  //圆的半径
            w:adaptation1(2),     //圆的弧度宽
            color:"#FFFFFF",  //画笔原色
            s:1*Math.PI/6,       //起始角
            e:2*Math.PI/5,    //结束角
            c:false             //旋转方向
        };
        drawArc(ctx,circle);

        var circle = {
            x: adaptation1(width/2),     //圆心的x轴坐标值
            y: adaptation1(height/2),    //圆心的y轴坐标值
            r: adaptation1(width/2-75),  //圆的半径
            w:adaptation1(1),     //圆的弧度宽
            color:"#e0e3e8",  //画笔原色
            s:2*Math.PI/4 ,      //起始角
            e:5*Math.PI/5,    //结束角
            c:false             //旋转方向
        };
        drawArc(ctx,circle);

        var circle = {
            x: adaptation1(width/2),     //圆心的x轴坐标值
            y: adaptation1(height/2),    //圆心的y轴坐标值
            r: adaptation1(width/2-75),  //圆的半径
            w:adaptation1(2),     //圆的弧度宽
            color:"#353d4d",  //画笔原色
            s:6*Math.PI/5 ,      //起始角
            e:9*Math.PI/6,    //结束角
            c:false             //旋转方向
        };
        drawArc(ctx,circle);

        var circle = {
            x: adaptation1(width/2),     //圆心的x轴坐标值
            y: adaptation1(height/2),    //圆心的y轴坐标值
            r: adaptation1(width/2-70),  //圆的半径
            w:adaptation1(7),     //圆的弧度宽
            color:"rgba(29,40,61,0.5)",  //画笔原色
            s:0 ,      //起始角
            e:2*Math.PI,    //结束角
            c:false             //旋转方向
        };
        drawArc(ctx,circle);

        var circle = {
            x: adaptation1(width/2),     //圆心的x轴坐标值
            y: adaptation1(height/2),    //圆心的y轴坐标值
            r: adaptation1(width/2-55),  //圆的半径
            w:adaptation1(2),     //圆的弧度宽
            color:"#FFFFFF",  //画笔原色
            s:Math.PI/7 ,      //起始角
            e:3*Math.PI/9,    //结束角
            c:false             //旋转方向
        };
        drawArc(ctx,circle);

        var circle = {
            x: adaptation1(width/2),     //圆心的x轴坐标值
            y: adaptation1(height/2),    //圆心的y轴坐标值
            r: adaptation1(width/2-64),  //圆的半径
            w:adaptation1(2),     //圆的弧度宽
            color:"#FFFFFF",  //画笔原色
            s:1*Math.PI/3 ,      //起始角
            e:6*Math.PI/9,    //结束角
            c:false             //旋转方向
        };
        drawArc(ctx,circle);

        var circle = {
            x: adaptation1(width/2),     //圆心的x轴坐标值
            y: adaptation1(height/2),    //圆心的y轴坐标值
            r: adaptation1(width/2-48),  //圆的半径
            w:adaptation1(2),     //圆的弧度宽
            color:"#FFFFFF",  //画笔原色
            s:5*Math.PI/8,      //起始角
            e:7*Math.PI/9,    //结束角
            c:false             //旋转方向
        };
        drawArc(ctx,circle);

        var circle = {
            x: adaptation1(width/2),     //圆心的x轴坐标值
            y: adaptation1(height/2),    //圆心的y轴坐标值
            r: adaptation1(width/2-58),  //圆的半径
            w:adaptation1(1),     //圆的弧度宽
            color:"#FFFFFF",  //画笔原色
            s:6*Math.PI/7,      //起始角
            e:6*Math.PI/5,    //结束角
            c:false             //旋转方向
        };
        drawArc(ctx,circle);

        var circle = {
            x: adaptation1(width/2),     //圆心的x轴坐标值
            y: adaptation1(height/2),    //圆心的y轴坐标值
            r: adaptation1(width/2-48),  //圆的半径
            w:adaptation1(1),     //圆的弧度宽
            color:"#FFFFFF",  //画笔原色
            s:8*Math.PI/7,      //起始角
            e:7*Math.PI/5,    //结束角
            c:false             //旋转方向
        };
        drawArc(ctx,circle);

        var circle = {
            x: adaptation1(width/2),     //圆心的x轴坐标值
            y: adaptation1(height/2),    //圆心的y轴坐标值
            r: adaptation1(width/2-48),  //圆的半径
            w:adaptation1(1),     //圆的弧度宽
            color:"#FFFFFF",  //画笔原色
            s:8*Math.PI/5,      //起始角
            e:10*Math.PI/5,    //结束角
            c:false             //旋转方向
        };
        drawArc(ctx,circle);

    }
}
/***绘制主图表动态部分***/
function drawChartMainDynamic(dom) {
    var width = dom.width*16/fontSize;
    var height = dom.height*16/fontSize;
    if(dom.getContext) {
        //获取对应的CanvasRenderingContext2D对象(画笔)
        var ctx = dom.getContext("2d");
        //中心
        var circle = {
            x: adaptation1(width / 2),     //圆心的x轴坐标值
            y: adaptation1(height / 2),    //圆心的y轴坐标值
            r: adaptation1(width / 2 - 230),  //圆的半径
            w: adaptation1(10),     //圆的弧度宽
            color: "#687080",  //画笔原色
            s: 2 * Math.PI / 3,       //起始角
            e: 2 * Math.PI / 3 + 0.105 * Math.PI,    //结束角
            c: false,             //旋转方向
            deg: 20,
            len: 5,
            speed: 200
        };
        drawDynamic(ctx, circle);
        //外边框
        var circle = {
            x: adaptation1(width / 2),     //圆心的x轴坐标值
            y: adaptation1(height / 2),    //圆心的y轴坐标值
            r: adaptation1(width / 2 - 32),  //圆的半径
            w: adaptation1(15),     //圆的弧度宽
            color: "#687080",  //画笔原色
            s: 6 * Math.PI / 5,       //起始角
            e: 6 * Math.PI / 5 + 0.020 * Math.PI,    //结束角
            c: false,             //旋转方向
            deg: 6,
            len: 14,
            speed: 200
        };
        drawDynamic(ctx, circle);

        //外边框
        var circle = {
            x: adaptation1(width / 2-3),     //圆心的x轴坐标值
            y: adaptation1(height / 2+5),    //圆心的y轴坐标值
            r: adaptation1(width / 2 - 25),  //圆的半径
            w: adaptation1(3.2),     //圆的弧度宽
            color: "#687080",  //画笔原色
            s:10 * Math.PI / 6 + 0.055 * Math.PI ,       //起始角
            e:10 * Math.PI / 6 + 0.058 * Math.PI,    //结束角
            c: false,             //旋转方向
            deg: 6,
            len: 43,
            speed: 200
        };
        drawDynamic(ctx, circle);
    }
}
/**添加监听事件*/
function addEven(dom,pieConfi,fun) {
    //添加事件监听
    dom.addEventListener("touchstart",function (event) {
        addTochMonitor(event,pieConfi,function (i) {
            fun(i)
        });
    },false)
    // if(document.hasOwnProperty("ontouchstart")) {
    //
    // }
    // else {
    //     dom.addEventListener("click",function (event) {
    //         addClickMonitor(event,pieConfi,function (i) {
    //             fun(i)
    //         });
    //     },false)
    // }
}
//画圆狐
/***
 * 参数为Object
 * 对象属性有
 *   x:  //圆心的x轴坐标值
     y:  //圆心的y轴坐标值
     r:  //圆的半径
     w:  //圆的弧度宽
     c:  //弧度的颜色
     s   //起始角
     e   //结束角
 * **/
function drawArc(ctx,obj) {
    //开始一个新的绘制路径
    ctx.beginPath();
    //设置弧线的颜色为蓝色
    ctx.strokeStyle = obj.color;
    //设置圆的轨度宽
    ctx.lineWidth  = obj.w;
    //沿着坐标点(100,100)为圆心、半径为100px的圆的顺时针方向绘制弧线
    ctx.arc(obj.x, obj.y, obj.r,obj.s ,obj.e , obj.c);
    //按照指定的路径绘制弧线
    ctx.stroke();
}
/***
 * 参数为Object
 * 对象属性有
 *   x:  //圆心的x轴坐标值
 y:  //圆心的y轴坐标值
 r:  //圆的半径
 w:  //圆的弧度宽
 c:  //弧度的颜色
 s   //起始角
 e   //结束角
 * **/
/**
 * num:  数量
 * pi    弧度
 * d     间隔
 * */
function drawArcDouble(ctx,obj,num,pi) {
    var w = Math.abs(obj.e-obj.s);
    var d = Math.abs((pi-w*num)/(num-1));
    var obj = obj;
    for(var i=0;i<num;i++){
        var obj1 = {
            x: obj.x,     //圆心的x轴坐标值
            y: obj.y,    //圆心的y轴坐标值
            r: obj.r,  //圆的半径
            w: obj.w,     //圆的弧度宽
            color: obj.color,  //画笔原色
            s: obj.s+(w+d)*i,       //起始角
            e: obj.e+(w+d)*i,    //结束角
            c: obj.c,             //旋转方向
        };
        drawArc(ctx,obj1);
    }
}

/**
 * 方形橡皮擦
 * */
function eraser(cxt,obj) {
    cxt.save();//将当前以左上角坐标为(0,0)的上下文环境进行保存，这样是为了在接下来中要进行画布偏移后，可以进行还原当前的环境
    cxt.translate(obj.x,obj.y);
    cxt.rotate(obj.e-Math.PI/2+Math.PI/1000);//设定每次旋转的度数
    cxt.beginPath();
    cxt.moveTo(0,obj.r-obj.w/2-10);
    cxt.lineTo(obj.offset/2,obj.r-obj.w/2-10);
    cxt.lineTo(obj.offset/2,obj.r+obj.w/2+10);
    cxt.lineTo(-obj.offset/2,obj.r+obj.w/2+10);
    cxt.lineTo(-obj.offset/2,obj.r-obj.w/2-10);
    cxt.closePath();
    cxt.clip();
    cxt.clearRect(0,0,width,height);
    cxt.restore();//将当前为(500,400)的点还原为（0,0）,其实在save中就是将上下文环境保存到栈中，在restore下面对其进行还原
}
/***
 * 动态弧形线条
 * */
function drawDynamic(cxt,obj) {
    var len = obj.len;
    var time=0;//定义运动的执行次数
    run(cxt);
    function run(cxt) {
        for (var time = 0; time <=len; time++) {
            cxt.save();//将当前以左上角坐标为(0,0)的上下文环境进行保存，这样是为了在接下来中要进行画布偏移后，可以进行还原当前的环境
            cxt.translate(obj.x, obj.y);
            cxt.rotate(time * obj.deg * Math.PI / 180);//设定每次旋转的度数
            //开始一个新的绘制路径
            cxt.beginPath();
            //设置弧线的颜色为蓝色
            cxt.strokeStyle = obj.color;
            //设置圆的轨度宽
            cxt.lineWidth = obj.w;
            //沿着坐标点(100,100)为圆心、半径为100px的圆的顺时针方向绘制弧线
            cxt.arc(0, 0, obj.r, obj.s, obj.e, obj.c);
            //按照指定的路径绘制弧线
            cxt.stroke();
            cxt.restore();//将当前为(500,400)的点还原为（0,0）,其实在save中就是将上下文环境保存到栈中，在restore下面对其进行还原
        }
    }
}

/**
 * 修改图表
 *
 * **/
function alertChart(dom,pieConfi,fun) {
    //获取对应的CanvasRenderingContext2D对象(画笔)
    var ctx = dom.getContext("2d");
    ctx.clearRect(0,0,width,height);
    //通过回掉重新绘制装饰线圈
    fun();

    var oldCount = 0;
    var newCount = 0;
    var pie = pieConfi.pie;
    var data = pieConfi.data;
    var len = data.length;
    for (var i=0;i<len;i++){
        var circle = {
            x: pie.x,     //圆心的x轴坐标值
            y: pie.y,    //圆心的y轴坐标值
            r: pie.r,  //圆的半径
            w:pie.w,     //圆的弧度宽
            color:data[i].color,  //画笔原色
            s:0,       //起始角
            e:transformation(data[i].value,pie.offset,len,i),    //结束角
            c:false,             //旋转方向
            offset:pie.offset
        };
        if(i==0){
            circle.s = 0;
            circle.e = transformation(data[0].value,pie.offset,len,i);
        }else {
            oldCount += data[i-1].value;
            newCount = oldCount+data[i].value;
            circle.s = transformation(oldCount,pie.offset,len,i);
            circle.e = transformation(newCount,pie.offset,len,i);
        }

        // circle.s-=Math.PI/4;
        // circle.e-=Math.PI/4;



        drawArc(ctx,circle);
        eraser(ctx,circle);
    }
}
/***
 * 修改饼状图单个
 * **/
function alertSingle(dom,pieConfi,index) {
    var ctx = dom.getContext("2d");
    var pie = pieConfi.pie;
    var data = pieConfi.data;
    var len = data.length;
    var circle = {
        x: pie.x,     //圆心的x轴坐标值
        y: pie.y,    //圆心的y轴坐标值
        r: pie.r,  //圆的半径
        w:pie.w,     //圆的弧度宽
        color:data[index].color,  //画笔原色
        s:0,       //起始角
        e:0,    //结束角
        c:false             //旋转方向
    };
    if(index==0){
        circle.s = 0;
        circle.e = transformation(data[0].value,pie.offset,len,index);
    }else {
        var oldCount = 0;
        var newCount = 0;
        for (var i=1;i<=index;i++){
            oldCount += data[i-1].value;
            newCount = oldCount+data[i].value;
        }
        circle.s = transformation(oldCount,pie.offset,len,index);
        circle.e = transformation(newCount,pie.offset,len,index);
    }
    drawArc(ctx,circle);
}
/**
 *
 * 事件监听
 * **/
function addClickMonitor(event,pieConfi,fun) {
    var event = window.event || event;
    var dom = $(event.target || event.srcElement);
    var height = dom.height()/2;
    var width = dom.width()/2;
    var offsteLeft = dom.offset().left;
    var offsetTop = dom.offset().top;
    var pgeX = event.pageX;
    var pageY = event.pageY;
    var x = pgeX-offsteLeft-width/2;
    var y = height/2-(pageY-offsetTop);
    var b = Math.floor(Math.sqrt(Math.pow(x,2)+Math.pow(y,2)));
    var fag1 = b<=pieConfi.pie.r+(pieConfi.pie.w/2);
    var fag2 = b>=pieConfi.pie.r-(pieConfi.pie.w/2);
    if(fag1 && fag2){
        //计算角度
        var c = Math.sqrt(Math.pow(x-b,2)+Math.pow(y-0,2));
        var deg = "";
        if(y>=0){
            deg = 360-(180-2*Math.acos(c/(2*b))*180/Math.PI);
        }else {
            deg = 180-2*Math.acos(c/(2*b))*180/Math.PI;
        }

        //旋转角度偏移
        deg = deg -(360-75);
        if(deg<0){
            deg = 360+deg;
        }

        console.log(deg);
        var data = pieConfi.data;
        var oldCount=0;
        var newCount=0;
        for (var i=0;i<data.length;i++){
            if(i==0){
                if(deg>=0 && deg<=data[i].value*360){
                    //alertSingle(dom[0],pieConfi,i);
                    fun(i)
                }
            }else {
                oldCount += data[i-1].value;
                newCount = oldCount+data[i].value;
                if(deg>oldCount*360 && deg<=newCount*360){
                    //alertSingle(dom[0],pieConfi,i);
                    fun(i)
                }
            }
        }
    }
}


function addTochMonitor(event,pieConfi,fun)  {
    var event = window.event || event;
    var dom = $(event.target || event.srcElement);
    var height = dom.height();
    var width = dom.width();
    var offsteLeft = dom.offset().left;
    var offsetTop = dom.offset().top;
    var pgeX = event.targetTouches[0].pageX;
    var pageY = event.targetTouches[0].pageY;
    var x = pgeX-offsteLeft-width/2;
    var y = height/2-(pageY-offsetTop);
    var b = Math.sqrt(Math.pow(x,2)+Math.pow(y,2));
    var fag1 = b<=pieConfi.pie.r+(pieConfi.pie.w/2);
    var fag2 = b>=pieConfi.pie.r-(pieConfi.pie.w/2);
    if(fag1 && fag2){
        //计算角度
        var c = Math.sqrt(Math.pow(x-b,2)+Math.pow(y-0,2));
        var deg = "";
        if(y>=0){
            deg = 360-(180-2*Math.acos(c/(2*b))*180/Math.PI);
        }else {
            deg = 180-2*Math.acos(c/(2*b))*180/Math.PI;
        }

        //旋转角度偏移
        deg = deg -(360-75);
        if(deg<0){
            deg = 360+deg;
        }

        console.log(deg);

        var data = pieConfi.data;
        var oldCount=0;
        var newCount=0;
        for (var i=0;i<data.length;i++){
            if(i==0){
                if(deg>=0 && deg<=data[i].value*360){
                    //alertSingle(dom[0],pieConfi,i);
                    fun(i)
                }
            }else {
                oldCount += data[i-1].value;
                newCount = oldCount+data[i].value;
                if(deg>oldCount*360 && deg<=newCount*360){
                    //alertSingle(dom[0],pieConfi,i);
                    fun(i)
                }
            }
        }
    }
}

//百分比与弧度的转换
/**
 * percentage    百分比
 * spacing       间距的弧度
 * num           圆弧的段数
 * offsetNum     偏移数
 * **/
function transformation(percentage,spacing,num,offsetNum) {
    var offsetNum = 0;
    var num = 0;
    return (2-spacing*num)*Math.PI*percentage+offsetNum*spacing*Math.PI;
}
/***
 * 计算圆心的偏移值
 * radian:圆弧的弧度
 * offset:偏移值
 * */
function circleTransformation(radian,offset) {
    var obj = {
        x:Math.cos(radian/2)*offset,
        y:Math.sin(radian/2)*offset
    }
    return obj
}
/***
 * 手机尺寸适配
 * 像素
 * */
function adaptation1(px) {
    return px/16*fontSize;
}
/**完整的对象克隆w**/
function clone(obj)
{
    var o,i,j,k;
    if(typeof(obj)!="object" || obj===null)return obj;
    if(obj instanceof(Array))
    {
        o=[];
        i=0;j=obj.length;
        for(;i<j;i++)
        {
            if(typeof(obj[i])=="object" && obj[i]!=null)
            {
                o[i]=arguments.callee(obj[i]);
            }
            else
            {
                o[i]=obj[i];
            }
        }
    }
    else
    {
        o={};
        for(i in obj)
        {
            if(typeof(obj[i])=="object" && obj[i]!=null)
            {
                o[i]=arguments.callee(obj[i]);
            }
            else
            {
                o[i]=obj[i];
            }
        }
    }
    return o;
}